home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
sticpsrc.lzh
/
SOURCE.ARC
/
TNC2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-28
|
35KB
|
1,366 lines
/* TNC-2 emulator for use by RLI or MBL bbs (or other programs) */
#include <ctype.h>
#include <time.h>
#include "global.h"
#include "mbuf.h"
#include "iface.h"
#include "timer.h"
#include "ax25.h"
#include "lapb.h"
#include "kiss.h"
#include "slip.h"
#include "tnc2.h"
#undef ALLCMDS 1 /* include unsupported cmds? */
#define BEACON 1 /* include BEACON possibility? */
struct tnc *tnc2s = NULLTNC; /* TNC controlblocks */
static void tnc2_recv(); /* upcall handlers */
/* TNC commands supported by the emulator */
static void dotnconmode(),dotnconnect(),dotnconverse(),
dotncstatus(),dotndaytime(),dotndiscon(),dotndisplay(),
dotnmycall(),dotnrestart(),dotntrans(),dotnunproto();
void dotnmheard(),dotnreset();
static struct tnccommand tnccommands[] =
{
"8BITCONV", TC_ON_OFF, 0, NULLVFP,
#ifdef ALLCMDS
"AX25L2V2", TC_ON_OFF, 1, NULLVFP, /* not used */
#endif
"AUTOLF", TC_ON_OFF, 2, NULLVFP,
#ifdef ALLCMDS
"AWLEN", TC_DECVAL, 3, NULLVFP, /* not used */
"AXDELAY", TC_DECVAL, 4, NULLVFP, /* not used */
"AXHANG", TC_DECVAL, 5, NULLVFP, /* not used */
#endif
#if (defined(BEACON) || defined(ALLCMDS))
"BEACON", TC_TIMER, 0, (void (*)()) 10000,
#endif
"BBSMSGS", TC_ON_OFF, 55, NULLVFP,
"BKONDEL", TC_ON_OFF, 6, NULLVFP,
#if (defined(BEACON) || defined(ALLCMDS))
"BTEXT", TC_TEXT, 0, NULLVFP,
#endif
#ifdef ALLCMDS
"BUDLIST", TC_ON_OFF, 7, NULLVFP, /* not used */
#endif
"CONNECT", TC_EXEC, 0, dotnconnect,
"CBELL", TC_ON_OFF, 8, NULLVFP,
#ifdef ALLCMDS
"CONPERM", TC_ON_OFF, 9, NULLVFP, /* not used */
"CHECK", TC_DECVAL, 10, NULLVFP, /* not used */
"CLKADJ", TC_DECVAL, 11, NULLVFP, /* not used */
#endif
"CMDTIME", TC_DECVAL, 12, NULLVFP,
"CMSG", TC_ON_OFF, 13, NULLVFP,
"CMSGDISC", TC_ON_OFF, 14, NULLVFP,
"CPACTIME", TC_ON_OFF, 15, NULLVFP,
"CR", TC_ON_OFF, 16, NULLVFP,
"CSTATUS", TC_EXEC, 0, dotncstatus,
"CTEXT", TC_TEXT, 1, NULLVFP,
"CANLINE", TC_HEXVAL, 17, NULLVFP,
"COMMAND", TC_HEXVAL, 18, NULLVFP,
#ifdef ALLCMDS
"CALSET", TC_DECVAL, 19, NULLVFP, /* not used */
#endif
"CANPAC", TC_HEXVAL, 20, NULLVFP,
"CONOK", TC_ON_OFF, 21, NULLVFP,
"CONMODE", TC_MISC, 0, dotnconmode,
"CONSTAMP", TC_ON_OFF, 22, NULLVFP,
"CONVERSE", TC_EXEC, 0, dotnconverse,
"DISCONNE", TC_EXEC, 0, dotndiscon,
"DAYTIME", TC_EXEC, 0, dotndaytime,
"DAYUSA", TC_ON_OFF, 23, NULLVFP,
"DELETE", TC_ON_OFF, 24, NULLVFP,
#ifdef ALLCMDS
"DWAIT", TC_DECVAL, 25, NULLVFP, /* not used */
"DIGIPEAT", TC_ON_OFF, 26, NULLVFP, /* not used */
#endif
"DISPLAY", TC_EXEC, 0, dotndisplay,
"ECHO", TC_ON_OFF, 27, NULLVFP,
#ifdef ALLCMDS
"ESCAPE", TC_ON_OFF, 28, NULLVFP, /* not used */
#endif
"FLOW", TC_ON_OFF, 29, NULLVFP,
#ifdef ALLCMDS
"FRACK", TC_DECVAL, 30, NULLVFP, /* not used */
"FULLDUP", TC_ON_OFF, 31, NULLVFP, /* not used */
"HEADERLN", TC_ON_OFF, 32, NULLVFP, /* not used */
"HEALLED", TC_ON_OFF, 33, NULLVFP, /* not used */
"HID", TC_ON_OFF, 34, NULLVFP, /* not used */
"ID", TC_EXEC, 0, NULLVFP,
#endif
"K", TC_EXEC, 0, dotnconverse, /* ALIAS for CONVERSE */
"KISS", TC_ON_OFF, 76, NULLVFP,
"KISSRX", TC_DECVAL, 77, NULLVFP,
#ifdef ALLCMDS
"LCOK", TC_ON_OFF, 35, NULLVFP, /* not used */
#endif
"LFADD", TC_ON_OFF, 36, NULLVFP,
"LFIGNORE", TC_ON_OFF, 37, NULLVFP,
#ifdef ALLCMDS
"LCALLS", TC_TEXT, 2, NULLVFP, /* not used */
"LCSTREAM", TC_ON_OFF, 38, NULLVFP, /* not used */
#endif
"MONITOR", TC_ON_OFF, 39, NULLVFP, /* not used, incl for BBS */
#ifdef ALLCMDS
"MALL", TC_ON_OFF, 40, NULLVFP, /* not used */
"MCON", TC_ON_OFF, 41, NULLVFP, /* not used */
"MFILTER", TC_MISC, 1, NULLVFP, /* not used */
#endif
"MHEARD", TC_EXEC, 0, dotnmheard,
#ifdef ALLCMDS
"MHCLEAR", TC_EXEC, 0, NULLVFP,
"MRPT", TC_ON_OFF, 42, NULLVFP, /* not used */
"MSTAMP", TC_ON_OFF, 43, NULLVFP, /* not used */
#endif
"MYCALL", TC_EXEC, 0, dotnmycall,
#ifdef ALLCMDS
"MYALIAS", TC_TEXT, 3, NULLVFP, /* not used */
"MAXFRAME", TC_DECVAL, 44, NULLVFP, /* not used */
"MCOM", TC_ON_OFF, 45, NULLVFP, /* not used */
#endif
"NEWMODE", TC_ON_OFF, 46, NULLVFP,
"NOMODE", TC_ON_OFF, 47, NULLVFP,
#ifdef ALLCMDS
"NUCR", TC_ON_OFF, 48, NULLVFP, /* not used */
"NULF", TC_ON_OFF, 49, NULLVFP, /* not used */
"NULLS", TC_DECVAL, 50, NULLVFP, /* not used */
#endif
"PACLEN", TC_DECVAL, 51, NULLVFP,
#ifdef ALLCMDS
"PARITY", TC_DECVAL, 52, NULLVFP, /* not used */
#endif
"PASS", TC_HEXVAL, 53, NULLVFP,
#ifdef ALLCMDS
"PASSALL", TC_ON_OFF, 54, NULLVFP, /* not used */
#endif
"PACTIME", TC_TIMER, 1, (void (*)()) 100,
#ifdef ALLCMDS
"RETRY", TC_DECVAL, 56, NULLVFP, /* not used */
#endif
"REDISPLA", TC_HEXVAL, 57, NULLVFP,
#ifdef ALLCMDS
"RECONNEC", TC_EXEC, 0, NULLVFP,
"RESPTIME", TC_DECVAL, 58, NULLVFP, /* not used */
#endif
"RESTART", TC_EXEC, 0, dotnrestart,
"RESET", TC_EXEC, 0, dotnreset,
"RXBLOCK", TC_ON_OFF, 59, NULLVFP,
#ifdef ALLCMDS
"SCREENLN", TC_DECVAL, 60, NULLVFP, /* not used */
#endif
"SENDPAC", TC_HEXVAL, 61, NULLVFP,
"START", TC_HEXVAL, 62, NULLVFP,
"STOP", TC_HEXVAL, 63, NULLVFP,
#ifdef ALLCMDS
"STREAMSW", TC_HEXVAL, 64, NULLVFP, /* not used */
"STREAMCA", TC_ON_OFF, 65, NULLVFP, /* not used */
"STREAMDB", TC_ON_OFF, 66, NULLVFP, /* not used */
#endif
"TRANS", TC_EXEC, 0, dotntrans,
#ifdef ALLCMDS
"TRIES", TC_EXEC, 0, NULLVFP, /* not used */
#endif
"TRFLOW", TC_ON_OFF, 67, NULLVFP,
#ifdef ALLCMDS
"TRACE", TC_ON_OFF, 68, NULLVFP, /* not used */
"TXDELAY", TC_DECVAL, 69, NULLVFP, /* not used */
#endif
"TXFLOW", TC_ON_OFF, 70, NULLVFP,
"TXUIFRAM", TC_ON_OFF, 78, NULLVFP,
"UNPROTO", TC_EXEC, 0, dotnunproto,
#ifdef ALLCMDS
"USERS", TC_DECVAL, 71, NULLVFP, /* not used */
#endif
"XFLOW", TC_ON_OFF, 72, NULLVFP,
#ifdef ALLCMDS
"XMITOK", TC_ON_OFF, 73, NULLVFP, /* not used */
#endif
"XOFF", TC_HEXVAL, 74, NULLVFP,
"XON", TC_HEXVAL, 75, NULLVFP,
"", 0, 0, NULLVFP
};
static char def_params[] = {
0, 1, 1, 7, 0, 0, 1, 0, 0, 0, 30, 0, 1, 0, 0, 0,
1, 0x18, 0x03, 0, 0x19, /*1*/ 0, 0, 1, 0, 16, 1, 1, 0, 1, 3, 0,
0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 2, 1, 0, 0,
0, 0, 0, 128, 3, 0x16, 0, 0, 10, 0x12, 0, 0, 80, 0x0d, 0x11, 0x13,
0x7c, 0, 0, 0, 0, 30, 0, 1, 1, 1, 0x13, 0x11, 0, 1, 0
};
char tnc2_prompt[] = "cmd:";
static char tnc2_bad[] = "?bad\r";
static char tnc2_call[] = "?call\r";
static char tnc2_notenough[] = "?not enough\r";
static char tnc2_toomany[] = "?too many\r";
static char tnc2_was[] = "was ";
static char tnc2_conrq[] = "*** connect request:";
static char tnc2_bslcr[] = "\\\r";
static char tnc2_cr[] = "\r";
extern char *ax25mesgs[];
/* send message to client (BBS) */
void
tnc2_mesg (tnc2,s)
register struct tnc *tnc2;
register unsigned char *s;
{
while (*s) {
if (!tnc2_ochar(tnc2,*s))
break;
if (*s++ == '\r' && tnc2->param[2]) /* AUTOLF */
if (!tnc2_ochar(tnc2,'\n'))
break;
}
}
/* process character input in cooked mode, return 1 if line complete */
int
tnc2_line (tnc2,c)
register struct tnc *tnc2;
register char c;
{
if (tnc2->passc) { /* prev was PASS char? */
tnc2->passc = 0; /* clear the flag */
tnc2->linebuf[tnc2->linepos++] = c; /* store the passed char */
tnc2->linebuf[tnc2->linepos] = '\0';
if (tnc2->param[27]) /* ECHO ON */
tnc2_mesg(tnc2,tnc2->linebuf + tnc2->linepos - 1); /* echo it */
goto checkbuf;
}
if (tnc2->param[17] && c == tnc2->param[17]) { /* CANLINE character */
while (tnc2->linepos > 0)
if (tnc2->linebuf[--(tnc2->linepos)] == '\r') {/* up to CR */
tnc2->linepos++;
break;
}
tnc2_mesg(tnc2,tnc2_bslcr);
return TL_CANCEL;
}
if (tnc2->param[18] && c == tnc2->param[18]) /* COMMAND character */
return TL_COMMAND;
if (tnc2->param[20] && c == tnc2->p